package io.renren.modules.wyzs.mobile_BillAdapterMoudle;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import io.renren.modules.wyzs.mobile_EnumMoudle.EnumDataExecType;

public class OwnEntry {
    public Integer Page;
    public String View;
    public HashMap<String, OwnColumn> Columns = new HashMap<String, OwnColumn>();
    public List<OwnRow> Rows = new LinkedList<OwnRow>();
    public List<OwnRow> DeleteRows = new LinkedList<OwnRow>();

    public void DeleteRow(int index)
    {
        if (Rows.size() - 1 >= index)
        {
            OwnRow row = Rows.get(index);
            if (row.DataExecType != EnumDataExecType.Insert)
            {
                DeleteRows.add(Rows.get(index));
            }
            
            Rows.get(index).DataExecType = EnumDataExecType.Delete;
            Rows.remove(index);
            OrderIndex();
        }
    }
    
    public Integer getPage(){
    	return this.Page;
    }

    private void OrderIndex()
    {
        int index = 0;
        for (OwnRow ownRow : Rows) {
        	ownRow.setIndex(index); 
            index++;
		}

    }

    public int AddRow()
    {
        OwnRow row = new OwnRow();
        row.DataExecType = EnumDataExecType.Insert;
        row.setIndex(Rows.size()); 

        int viewIndex = 0;
        for(OwnColumn col:Columns.values()){
            OwnField field = new OwnField(col.FieldTemp);
            row.Fields.put(field.getFieldTemp().getKey(), field);
        }

        Rows.add(row);
        return row.getIndex();
    }
}
